<template>
  <section>
    <el-select v-model="row.val" filterable remote reserve-keyword placeholder="请输入优惠券关键词" :remote-method="remoteMethod" size="mini">
      <el-option v-for="couponDefine in couponDefineList" :key="couponDefine.code" :label="couponDefine.title" :value="couponDefine.id">
      </el-option>
    </el-select>
  </section>
</template>

<script>
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  export default {
    name: "sendCoupon",
    props: ['row','activity'],
    data(){
      return{
        couponDefineList:null
      }
    },
    created(){
      console.log('row&act----',this.row,this.activity)
      if(this.row.val) this.getCouponDefine(this.row.val)
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getCouponDefine(id){
        this.fetch({name:"getCouponDefine",data:{id}})
          .then(res=>{
            this.couponDefineList=[res]
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      remoteMethod(key){
        this.getCouponDefineList(key)
      },
      getCouponDefineList(key){
        this.fetch({name:"getCouponDefineList",data:{key,departmentId:this.activity.departmentId}})
          .then(res=>{
            // console.log('优惠券列表',res)
            this.couponDefineList=res.content
            this.totalPage=res.totalPages
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      }
    }
  }
</script>

<style scoped>

</style>
